package com.baize.motionlayoutdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.transition.Scene
import androidx.transition.TransitionManager

/**
 * 过渡动画二：使用TransitionManager#go 实现复杂场景的过渡
 */
class TransitionGoActivity : AppCompatActivity(), View.OnClickListener {

  var toggle  = true

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_transition_go)
    bindData()
  }

  fun bindData() {
    findViewById<ImageView>(R.id.iv_image).setOnClickListener(this)
    findViewById<TextView>(R.id.tv_text).setText(R.string.stage)
    findViewById<TextView>(R.id.tv_stage).setText(R.string.stage_long)
  }

  override fun onClick(v: View) {
    val root: ViewGroup = findViewById(R.id.root)
    val startScene = Scene.getSceneForLayout(root, R.layout.activity_transition_go_start, this) //开始场景
    val endScene = Scene.getSceneForLayout(root, R.layout.activity_transition_go_end, this) //结束场景

    if (toggle) {
      TransitionManager.go(endScene)
    } else {
      TransitionManager.go(startScene)
    }
    bindData() //View对象已经不是同一个，需要重新绑定数据
    toggle = !toggle
  }
}